//
//  CustomAnnotaionShowView.m
//  CooperLinker
//
//  Created by 张 晓军 on 16/4/11.
//  Copyright © 2016年 洪雯. All rights reserved.
//

#import "CustomAnnotaionShowView.h"
#define kCalloutWidth       40.0
#define kCalloutHeight      50.0


@interface CustomAnnotaionShowView ()

@property (nonatomic, strong, readwrite) CustomCalloutShowView *calloutView;

@end

@implementation CustomAnnotaionShowView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/


- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    if (self.selected == selected)
    {
        return;
    }
    
    if (selected)
    {
        if (self.calloutView == nil)
        {
            self.calloutView = [[CustomCalloutShowView alloc] initWithFrame:CGRectMake(0, 0, kCalloutWidth, kCalloutHeight)];
            self.calloutView.center = CGPointMake(CGRectGetWidth(self.bounds) / 2.f + self.calloutOffset.x,
                                                  -CGRectGetHeight(self.calloutView.bounds) / 2.f + self.calloutOffset.y);
        }
    
        self.calloutView.image = self.imageName.image;
        self.calloutView.title = self.annotation.title;
        self.calloutView.subtitle = self.annotation.subtitle;
        [self addSubview:self.calloutView];
    }
    else
    {
        [self.calloutView removeFromSuperview];
    }
    
    [super setSelected:selected animated:animated];
}

@end
